<?php
// 获取单个用户信息
// header("content-type:text/html;charset=utf-8");
include_once("conn.php");

$uid = $_GET['uid'];

$status = '没有在进行中的订单';
$tips = '可以封禁，用户在您进行操作后将不可进行登录';
$dis = "onclick='return blockingUser();'";
$btype = 'submit';

$sql_1 = "SELECT * FROM tb_user_info WHERE uid = '" . $uid . "'";
$result_1 = mysqli_query($conn, $sql_1);
if ($result_1) {
    if (mysqli_num_rows($result_1) > 0) {
        $row_1 = mysqli_fetch_assoc($result_1);
        if ($row_1['ustatus'] == '禁用') {
            $status = '用户已封禁';
            $tips = '用户已封禁';
            $dis = 'disabled';
            $btype = 'button';
        }
    } else {
        echo "查询用户ID为：'" . $uid . "'的用户不存在，请确认用户ID是否正确";
        die();
    }
} else {
    echo "查询用户失败，请确认用户ID是否正确";
    die();
}

$sql_2 = "SELECT * FROM tb_order_info WHERE uid = '" . $uid . "' AND o_status != '2' AND o_status != '-1'";
$result_2 = mysqli_query($conn, $sql_2);
if ($result_2) {
    $num_2 = mysqli_num_rows($result_2);
    if ($num_2 > 0) {
        $status = '有正在进行中的订单';
        $tips = '无法封禁，用户有正在进行中的订单';
        $dis = 'disabled';
        $btype = 'button';
    }
} else {
    echo "查询用户失败，请确认用户ID是否正确";
    die();
}

echo "
<form action='php/blocking-user.php' class='blocking-form' method='post'>
    <div class='mb-3 row'>
        <label for='uid' class='col-sm-6 col-form-label'>用户ID</label>
        <div class='col-sm-6'>
            <input type='text' readonly class='form-control-plaintext' id='uid' name='uid' value='" . $row_1['uid'] . "'>
        </div>
    </div>
    <div class='mb-3 row'>
        <label for='uname' class='col-sm-6 col-form-label'>用户昵称</label>
        <div class='col-sm-6'>
            <input type='text' readonly class='form-control-plaintext' id='uname' value='" . $row_1['uname'] . "'>
        </div>
    </div>
    <div class='mb-3 row'>
        <label for='status' class='col-sm-6 col-form-label'>订单状态</label>
        <div class='col-sm-6'>
            <input type='text' readonly class='form-control-plaintext' id='status' value='" . $status . "'>
        </div>
    </div>
    <div class='mb-3 row'>
        <label for='tips' class='col-sm-6 col-form-label'>提示</label>
        <div class='col-sm-6'>
            <input type='text' readonly class='form-control-plaintext' id='tips' value='" . $tips . "'>
        </div>
    </div>
    <div class='btndiv'>
        <button type='" . $btype . "' class='btn btn-outline-danger' " . $dis . ">禁用该用户</button>
    </div>
</form>";
